package com.lins.framework.ui.home.date;

import android.app.DatePickerDialog;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.Toast;

import com.lins.framework.R;
import com.lins.framework.common.base.BaseActivity;
import com.lins.framework.utils.DateUtil;
import com.lins.framework.widget.FixedHoloDatePickerDialog;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DatePickerActivity extends BaseActivity {

    Button btn;
    TextView et;

    private int year, month, day;

    private Context context;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_datepicker);
        context = this;
        btn = findViewById(R.id.dateBtn);
        et = findViewById(R.id.et);

        //获取当前日期
        Calendar calendar = Calendar.getInstance();
        year = calendar.get(Calendar.YEAR);
        month = calendar.get(Calendar.MONTH);
        day = calendar.get(Calendar.DAY_OF_MONTH);

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
    }


    private void showDate() {
        if (Build.VERSION.SDK_INT >= 24) {
            FixedHoloDatePickerDialog datePicker = new FixedHoloDatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
                @Override
                public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {

                }
            }
                    , year, month - 1, day); //上下文，点击回调,Calendar年月日
            datePicker.setHasNoDay(true);//只显示年月，隐藏掉日
            datePicker.show();
        } else {
            DatePickerDialog datePicker = new DatePickerDialog(context, DatePickerDialog.THEME_HOLO_LIGHT,
                    new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {

                        }
                    }
                    , year, month - 1, day); //上下文，点击回调,Calendar年月日
            datePicker.show();
            //只显示年月，隐藏掉日
            DatePicker dp = DateUtil.findDatePicker((ViewGroup) datePicker.getWindow().getDecorView());
            if (dp != null) {
                ((ViewGroup) ((ViewGroup) dp.getChildAt(0)).getChildAt(0))
                        .getChildAt(2).setVisibility(View.GONE);
            }
        }
    }


}



